//
//  UIButton+ZInit.m
//
//  Created by ZhàoYǒng on 2018/1/11.
//  Copyright © 2018年 ZhàoYǒng. All rights reserved.
//

#import "UIButton+ZInit.h"

@implementation UIButton(ZInit)

UIButton * _Nullable EmptyButton(SEL _Nullable action, id _Nullable target) {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = UIColor.clearColor;
    [button addTarget:target action:action
     forControlEvents:UIControlEventTouchUpInside];
    return button;
}

UIButton * _Nullable ImageButton(BOOL isBg, UIImage * _Nullable image, SEL _Nullable action, id _Nullable target) {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (isBg) {
        [button setBackgroundImage:image forState:UIControlStateNormal];
    } else {
        [button setImage:image forState:UIControlStateNormal];
    }
    [button addTarget:target action:action
     forControlEvents:UIControlEventTouchUpInside];
    return button;
}

UIButton * _Nullable TextButton(UIColor * _Nullable tint, CGFloat font, NSString * _Nullable title, BOOL isCustom, SEL _Nullable action, id _Nullable target) {
    UIButton *button = [UIButton buttonWithType:isCustom ? UIButtonTypeCustom : UIButtonTypeSystem];
    button.backgroundColor = UIColor.clearColor;
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:tint forState:UIControlStateNormal];
    [button addTarget:target action:action
     forControlEvents:UIControlEventTouchUpInside];
    return button;
}

UIButton * _Nullable SolidButton(UIColor * _Nullable bColor, UIColor * _Nullable tColor, CGFloat corner, CGFloat font, NSString * _Nullable title, SEL _Nullable action, id _Nullable target) {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    CGFloat inset = corner > 5.f ? corner : 5.f;
    button.contentEdgeInsets = UIEdgeInsetsMake(0, inset, 0, inset);
    button.backgroundColor = bColor;
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    if (corner > 0) {
        button.layer.cornerRadius = corner;
        button.clipsToBounds = YES;
    }
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:tColor forState:UIControlStateNormal];
    [button addTarget:target action:action
     forControlEvents:UIControlEventTouchUpInside];
    return button;
}

UIButton * _Nullable HollowButton(UIColor * _Nullable tint, CGFloat corner, CGFloat font, NSString * _Nullable title, SEL _Nullable action, id _Nullable target) {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    CGFloat inset = corner > 5.f ? corner : 5.f;
    button.contentEdgeInsets = UIEdgeInsetsMake(0, inset, 0, inset);
    button.backgroundColor = UIColor.clearColor;
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    button.layer.borderColor = tint.CGColor;
    button.layer.borderWidth = 1.f;
    if (corner > 0) {
        button.layer.cornerRadius = corner;
        button.clipsToBounds = YES;
    }
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:tint forState:UIControlStateNormal];
    [button addTarget:target action:action
     forControlEvents:UIControlEventTouchUpInside];
    return button;
}

@end
